Server-side Action Scripting

Description

Server-side action scripting makes it easy to add functionality to server-side events. For example, these actions can save data that was submitted from the client to the server, or populate client-side controls with data from a server, whenever the specified server-side event fires.

To add a server-side action to a server-side event first click the 'Action Scripting' button in the Server-side events page toolbar.

images/ssa2.png

Select the desired action to add it to the Xbasic server-side event.

images/ssa.png

Available Action Scripts

Name
Description
Save Submitted Data to Table(s)

Save the submitted data to one or more tables.

Send an e-mail message

Send an e-mail message. The message can use fields from the component.

Populate a Dialog with data from one or more tables

Populate the controls with data from one or more tables.

Load Web Security Values

Populate the controls with data from the web security system.

Validate Web Security Values

Validate data that will be saved in the web security system.

Save Web Security Values

Save submitted data to the web security system.

Change Web Security Password

Change a user's password in the web security system.

Load Primary keys for Parent Table

Get a list of all of the primary keys in a query and store in the Dialog object.

Post-processing After an Action Script has Run

In some situations, you may want to execute additional Xbasic based on the result of an Action Script (e.g. generate a custom error message if a record was not saved.) Some Action Scripts have variables that you can reference in your Xbasic after the script has run. To find out what variables are available, place the mouse cursor in the text for an Action Script and select Show variables exposed by this action option from the Action Scripting button.

Alpha Anywhere will open a window that lists the variables available to your Xbasic script. These variables can only be referenced after the ExecuteServerSideAction function call for the Action Script.

images/showExposedVariables.png

Sending JavaScript to the Client from a Server-side Event with an Action Script

Action Scripts may modify the e.javascript variable in an Xbasic server-side event. When sending JavaScript to the client from an event that includes a server-side Action Script, be sure to append your JavaScript to the e.javascript object to prevent accidentally overwriting JavaScript Alpha Anywhere has generated as part of the Action Script.

A pattern you may want to consider adopting for adding your own JavaScript to execute on the client in addition to JavaScript generated by an Action Script is shown below:

function afterDialogValidate as v (e as p)
    ' TIP: Some server-side actions do not add JavaScript to the e.javascript variable.
    ' If you set e.javascript to an empty string at the beginning of the event, it 
    ' creates the e.javascript property. This allows you to append JavaScript later 
    ' without having to test if the e.javascript variable exists. 
    ' The e.javascript variable doesn't exist until it has been assigned a value.
    e.javascript = ""

    'To edit this action, place insertion point anywhere in the command, then click the 'Action Scripting' button'.
    ExecuteServerSideAction("Save Data::Save_Submitted_Data_to_Table_s_")

    ' Add a message to show the user indicating whether or not the record was saved:
    if (rtc.flagRecordWasSaved) then
        ' TIP: Appending crlf() makes it easier to read the javascript returned from the
        ' callback using debugging tools in a web browser.
        e.javascript = e.javascript + "alert('Record was saved!');" + crlf()
    else
        e.javascript = e.javascript + "alert('Record was not saved!');" + crlf()
    end if

    ' Add multiple lines of javascript using delimiters:
    e.javascript = e.javascript + <<%js%
    var listObj = {dialog.object}.getControl("LIST1");
    if (listObj) {
        alert("LIST1 exists!");
    } else {
        alert("LIST1 does not exist.");
    }
%js%

'additional code, comments, etc
end function